package com.utils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
 *
 */
public class SetSorting {
    public static Set<String> sortByValue(Set<String> set){
        List<String> setList= new ArrayList<String>(set);
        Collections.sort(setList, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                // TODO Auto-generated method stub
                return o2.compareTo(o1);
            }

        });
        set = new LinkedHashSet<String>(setList);//这里注意使用LinkedHashSet
        return set;
    }
    public static void main(String[] args) {
        Set<String> set = new HashSet<String>();
        set.add("aaa");
        set.add("ccc");
        set.add("bbb");
        System.out.println(sortByValue(set));
    }
}
